const jwt = require("jsonwebtoken");
const { PRIVATE_KEY } = require("../config/secret");
class loginRouter {
  sign(ctx, next) {
    //1.获取用户信息
    const { id, name } = ctx.user;
    const token = jwt.sign({ id, name }, PRIVATE_KEY, {
      expiresIn: 60 * 60 * 24 * 30,
      algorithm: "RS256",
    });
    //3.返回用户信息
    ctx.body = {
      data: { id, name, access_token: token, code: 0 },
    };
  }
}
module.exports = new loginRouter();
